//
//  V4InputBuyerAndSeller.m
//  XinKaiFa55like
//
//  Created by 55like on 25/09/2017.
//  Copyright © 2017 55like lj. All rights reserved.
//

#import "V4InputBuyerAndSeller.h"
#import "MyUiIAlertView.h"
#import "MyUiActionSheet.h"
#import "SelectTitleViewController.h"
#import "PLTextView.h"
#import "AddImageView.h"
@interface V4InputBuyerAndSeller ()<UITextFieldDelegate>
{
    
    UIScrollView*scrollView;
    
}
@property(nonatomic,strong)AddImageView*  imageEditorV;
@property(nonatomic,weak)UITextView*tv;
@property(nonatomic,assign)BOOL isEdite;
@property(nonatomic,strong)NSDictionary*DataDic;
@property(nonatomic,assign)BOOL canEdite;
@property (nonatomic,strong)NSMutableArray * imageArray;
@property (nonatomic,strong)NSMutableArray * pathArray;
@property (nonatomic,strong)NSMutableArray * remArray;
@end

@implementation V4InputBuyerAndSeller
#pragma mark  开始
- (void)viewDidLoad {
    [super viewDidLoad];
    _canEdite=YES;
    if (self.otherInfo ) {
        _isEdite=YES;
        
        [self loadDATA];
    }else{
        _isEdite=NO;
        
        [self addView];
    }
    
}
#pragma mark -  写UI
-(void)addView{
      __weak __typeof(self) weakSelf = self;
    {
     WSSizeButton*btnpublish=[RHMethods buttonWithframe:CGRectMake(0, kScreenHeight-44, kScreenWidth, 44) backgroundColor:rgb(239,186,58) text:@"发布" font:17 textColor:rgb(255,255,255) radius:0 superview:self.view];
        [btnpublish addTarget:self action:@selector(OKBtnClik:) forControlEvents:UIControlEventTouchUpInside];
    
    }
    
    scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, kTopHeight, kScreenWidth, kScreenHeight-kTopHeight-44)];
    [self.view addSubview:scrollView];
    
    
    
    float myY=0.0;
    
    NSArray*arraytitle=@[@"姓名",@"性别",@"电话",@"微信",@"邮箱",@"性质",@"公司名称",@"分类",@"备注",@"标签",];
    if (_isEdite) {
       arraytitle=@[@"姓名",@"性别",@"电话",@"微信",@"邮箱",@"性质",@"公司名称",@"分类",@"备注",@"标签",@"录入者",@"跟踪者",];
    }
    
    
//    NSArray*arraytitle=@[@"姓名",@"性别",@"电话",@"微信",@"邮箱",@"性质",@"公司名称",@"分类",@"备注",@"标签",@"录入者",@"跟踪者",];
    for (int i=0; i<arraytitle.count; i++) {
        NSString*titleStr=arraytitle[i];
        
        UIView*view1=[self getAddValueForKey:titleStr];
        if (view1==nil) {
            view1=[RHMethods viewWithFrame:CGRectMake(0, myY, kScreenWidth, 40) backgroundcolor:zrgbwhiteColor superView:scrollView];
            [self setAddValue:view1 forKey:titleStr];
            UILabel*lb1=[RHMethods lableX:10 Y:13 W:0 Height:14 font:14 superview:view1 withColor:nil text:titleStr];
            UITextField*tf1=[RHMethods textFieldlWithFrame:CGRectMake(100, 0, kScreenWidth-110, view1.frameHeight) font:Font(14) color:nil placeholder:@"请输入" text:@""];
            tf1.delegate=self;
            [view1 addSubview:tf1];
            tf1.textAlignment=NSTextAlignmentRight;
            WSSizeButton*btn1=[RHMethods buttonWithframe:CGRectMake(0, 0, kScreenWidth, view1.frameHeight) backgroundColor:nil text:@"" font:12 textColor:rgb(51,51,51) radius:0 superview:view1];
            //        btn1.backgroundColor=rgbRedColor;
            [btn1 setImage:[UIImage imageNamed:@"xkf_searrighticon"] forState:UIControlStateNormal];
            [btn1 setImage:[UIImage imageNamed:@"xkf_xiala2"] forState:UIControlStateSelected];
            [btn1 setBtnLableFrame:CGRectMake(0, 0, btn1.frameWidth-10-15-10, btn1.frameHeight)];
            btn1.titleLabel.textAlignment=NSTextAlignmentRight;
            btn1.hidden=YES;
            [btn1 setBtnImageViewFrame:CGRectMake(btn1.frameWidth-10-15, 0.5*(btn1.frameHeight-15), 15, 15)];
            btn1.imageView.contentMode=UIViewContentModeScaleAspectFit;
            UIView*viewline=[RHMethods viewWithFrame:CGRectMake(0, view1.frameHeight-0.5, kScreenWidth, 0.5) backgroundcolor:rgb(220,220,220) superView:view1] ;
            [view1 setAddValue:btn1 forKey:@"btn1"];
            [view1 setAddValue:tf1 forKey:@"tf1"];
            [view1 setAddValue:viewline forKey:@"viewline"];
            [view1 setAddValue:lb1 forKey:@"lb1"];
            
        }
        
        WSSizeButton*btn1=[view1 getAddValueForKey:@"btn1"];
        UITextField*tf1=[view1 getAddValueForKey:@"tf1"];
        UILabel*lb1=[view1 getViewValueForKey:@"lb1"];
//        UIView*viewline=[view1 getAddValueForKey:@"viewline"];
        __weak __typeof(btn1) weakbtn1 = btn1;
        __weak __typeof(view1) weakview1 = view1;
        view1.userInteractionEnabled=_canEdite;
        
    
//        tf1.userInteractionEnabled=NO;
        
        
        
        if ([titleStr isEqualToString:@"姓名"]) {
           tf1.text= [_DataDic objectForKey:@"name"];
            
        }else  if ([titleStr isEqualToString:@"性别"]) {
            
//            tf1.text= [_DataDic objectForKey:@"name"];
            if ([[_DataDic objectForJSONKey:@"sex"]isEqualToString:@"1"]) {
                
                [weakview1 setAddValue:@"1" forKey:@"data"];
                [weakbtn1 setTitle:@"男" forState:UIControlStateNormal];
            }else  if ([[_DataDic objectForJSONKey:@"sex"]isEqualToString:@"2"]) {
                
                [weakview1 setAddValue:@"2" forKey:@"data"];
                [weakbtn1 setTitle:@"女" forState:UIControlStateNormal];
            }
            
            
            
            btn1.hidden=NO;
            tf1.hidden=YES;
          [btn1 addViewClickBlock:^(UIView *view) {
              [MyUiActionSheet showWithActionSheetBlock:^(UIActionSheet * _Nonnull actionSheet, NSInteger buttonIndex) {
                  
                  if (buttonIndex==1) {
                      [weakview1 setAddValue:@"1" forKey:@"data"];
                      [weakbtn1 setTitle:@"男" forState:UIControlStateNormal];
                  }else if(buttonIndex==2){
                      [weakview1 setAddValue:@"2" forKey:@"data"];
                      [weakbtn1 setTitle:@"女" forState:UIControlStateNormal];
                  }
                  
              } WithTitle:@"性别" cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"男",@"女",nil];
          }];
            
        }else  if ([titleStr isEqualToString:@"电话"]) {
            tf1.text= [_DataDic objectForKey:@"mobile"];
            
        }else  if ([titleStr isEqualToString:@"微信"]) {
            
            tf1.text= [_DataDic objectForKey:@"wechat"];
        }else  if ([titleStr isEqualToString:@"邮箱"]) {
            tf1.text= [_DataDic objectForKey:@"email"];
            
        }else  if ([titleStr isEqualToString:@"性质"]) {
            btn1.hidden=NO;
            tf1.hidden=YES;
            
            if ([[_DataDic objectForJSONKey:@"nature"]isEqualToString:@"1"]) {
                
                [weakview1 setAddValue:@"1" forKey:@"data"];
                [weakbtn1 setTitle:@"中介" forState:UIControlStateNormal];
            }else  if ([[_DataDic objectForJSONKey:@"nature"]isEqualToString:@"2"]) {
                
                [weakview1 setAddValue:@"2" forKey:@"data"];
                [weakbtn1 setTitle:@"直客" forState:UIControlStateNormal];
            }
            
            
         [btn1 addViewClickBlock:^(UIView *view) {
             [MyUiActionSheet showWithActionSheetBlock:^(UIActionSheet * _Nonnull actionSheet, NSInteger buttonIndex) {
                 
                 if (buttonIndex==1) {
                     [weakview1 setAddValue:@"1" forKey:@"data"];
                     [weakbtn1 setTitle:@"中介" forState:UIControlStateNormal];
                 }else if(buttonIndex==2){
                     [weakview1 setAddValue:@"2" forKey:@"data"];
                     [weakbtn1 setTitle:@"直客" forState:UIControlStateNormal];
                 }
                 
             } WithTitle:@"性质" cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"中介",@"直客",nil];
         }];
        }else  if ([titleStr isEqualToString:@"公司名称"]) {
            
            tf1.text= [_DataDic objectForKey:@"companyname"];
        }else  if ([titleStr isEqualToString:@"分类"]) {
            btn1.hidden=NO;
            tf1.hidden=YES;
            
            if (_DataDic) {
                [view1 setAddValue:[_DataDic objectForJSONKey:@"cid"] forKey:@"data"];
                [btn1 setTitle:[_DataDic objectForJSONKey:@"cname"] forState:UIControlStateNormal];
            }
            
            [btn1 addViewClickBlock:^(UIView *view) {
                NSMutableDictionary*mdic=[NSMutableDictionary new];
                [mdic setObject:[NSString stringWithFormat:@"%@",weakbtn1.currentTitle] forKey:@"currentTitle"];
                
                NSMutableArray*mtitlarray=[NSMutableArray new];
                
                NSArray*array=[UTILITY.userTypeData objectForKey:@"bigcate"];
                for (NSDictionary*dic in array) {
                    for (NSDictionary *subdic in [dic objectForJSONKey:@"list"]) {
                        NSMutableDictionary*submdic=[NSMutableDictionary dictionaryWithDictionary:subdic];
                        [submdic setObject:[subdic objectForKey:@"name"] forKey:@"title"];
                        
                        [mtitlarray addObject:submdic];
                    }
                }
                [mdic setObject:mtitlarray forKey:@"titleArray"];
                //            __weak __typeof(btn1) weakbtn1 = btn1;
                [weakSelf pushController:[SelectTitleViewController class] withInfo:nil withTitle:@"选择分类" withOther:mdic withAllBlock:^(id data, int status, NSString *msg) {
                    //                weaktxtfenlie.text=[data objectForJSONKey:@"title"];
                    [weakbtn1 setTitle:[data objectForJSONKey:@"title"] forState:UIControlStateNormal];
                    [weakview1 setAddValue:[data objectForJSONKey:@"id"] forKey:@"data"];
                    
                }];
 
            }];
        }else  if ([titleStr isEqualToString:@"备注"]) {
            
            view1.userInteractionEnabled=YES;
            btn1.hidden=NO;
//            btn1.selected=YES;
            tf1.hidden=YES;
            [btn1 addViewClickBlock:^(UIView *view) {
                UIButton*mbtn=(UIButton*)view;
                mbtn.selected=!mbtn.selected;
                UIView*viewReMark=[weakSelf getAddValueForKey:@"viewReMark"];
                if (weakbtn1.selected) {
                    weakview1.frameHeight=viewReMark.frameYH;
                    viewReMark.hidden=NO;
                }else{
                    viewReMark.hidden=YES;
                    weakview1.frameHeight=40;
                }
                [weakSelf reloadScrollView];
            }];
            {
                
                UIView*viewReMark=[self getAddValueForKey:@"viewReMark"];
                if(viewReMark==nil){
                
                    viewReMark=[RHMethods viewWithFrame:CGRectMake(0, 40, kScreenWidth, 171) backgroundcolor:zrgbwhiteColor superView:view1];
                    
                    viewReMark.hidden=YES;
                    PLTextView*tv=[[PLTextView alloc]initWithFrame:CGRectMake(0, 10, kScreenWidth, 68)];
                    [viewReMark addSubview:tv];
                    tv.Placeholder=@"请填写备注信息";
                    tv.font=Font(14);
                    
                    _tv.text=[_DataDic getAddValueForKey:@"descr"];
                    _tv=tv;
                    _tv.text=[_DataDic getAddValueForKey:@"descr"];
                    _tv.delegate=self;
                    
                    
                    
                    for (NSDictionary*dic in _DataDic[@"path"]) {
                        //                        NSMutableDictionary * imageData = [NSMutableDictionary new];
                        //                        [imageData setValue:[dic valueForJSONStrKey:@"id"] forKey:@"id"];
                        //                        [imageData setValue:[dic valueForJSONStrKey:@"url"] forKey:@"path"];
                        [self.imageArray addObject:[dic valueForJSONStrKey:@"url"]];
                    }
                    UIImage * image = [UIImage imageNamed:@"zdyadd"];
                    [self.imageArray addObject:image];
                    
                    AddImageView*  imageEditorV = [[AddImageView alloc] initWithFrame:CGRectMake(0,  88, kScreenWidth, ((self.imageArray.count % 4 == 0?0:1) + self.imageArray.count / 4) * (kScreenWidth - 20)/4)];
                    [viewReMark addSubview:imageEditorV];
                    _imageEditorV = imageEditorV;
                    
                    //                    ImageSelectEditorView*  imageEditorV=[[ImageSelectEditorView alloc] initWithFrame:CGRectMake(0,  88, kScreenWidth, 100)];
                    //                    _imageEditorV=imageEditorV;
                    //                    [viewReMark addSubview:imageEditorV];
                    __weak __typeof(viewReMark) weakviewReMark = viewReMark;
                    //                    __weak __typeof(viewReMark) weakviewReMark = viewReMark;
                    __weak __typeof(imageEditorV) wimageEditorV = imageEditorV;
                    
                    
                    imageEditorV.imageArray = self.imageArray;
                    [imageEditorV reshData];
                    imageEditorV.remBlock = ^(NSInteger row) {
                        
                        
                        if (weakSelf.pathArray.count > row) {
                            
                            NSString * idd = [[weakSelf.pathArray[row] valueForJSONStrKey:@"id"] mutableCopy];
                            [weakSelf.remArray addObject:idd];
                            [weakSelf.pathArray removeObjectAtIndex:row];
                        }
                        
                    };
                    imageEditorV.imageBlock = ^(NSMutableArray *imageArr, CGFloat cH) {
                        
                        
                        weakSelf.imageArray = imageArr;

                        if ([weakSelf getAddValueForKey:@"标签"]) {
                            weakviewReMark.frameHeight=wimageEditorV.frameYH+10;
                            if (weakbtn1.selected) {
                                
                                weakview1.frameHeight=weakviewReMark.frameYH;
                            }else{
                                
                                weakview1.frameHeight=40;
                            }
                            [weakSelf reloadScrollView];
                        }
                        
                    };
       
                    weakviewReMark.frameHeight=wimageEditorV.frameYH+10;
                    if (weakbtn1.selected) {
                        
                        weakview1.frameHeight=weakviewReMark.frameYH;
                    }else{
                        
                        weakview1.frameHeight=40;
                    }
                    [weakSelf reloadScrollView];
                    
                    [viewReMark setAddValue:tv forKey:@"tv"];
                    [viewReMark setAddValue:imageEditorV forKey:@"imageEditorV"];
                    [self setAddValue:viewReMark forKey:@"viewReMark"];
                }
            
            }
            
            
            
            
            
        }else  if ([titleStr isEqualToString:@"标签"]) {
            btn1.hidden=NO;
            tf1.hidden=YES;
            
            
            
            if ([[_DataDic objectForJSONKey:@"sharetype"]isEqualToString:@"1"]) {
                
                [weakview1 setAddValue:@"1" forKey:@"data"];
                [weakbtn1 setTitle:@"自有" forState:UIControlStateNormal];
            }else  if ([[_DataDic objectForJSONKey:@"sharetype"]isEqualToString:@"2"]) {
                
                [weakview1 setAddValue:@"2" forKey:@"data"];
                [weakbtn1 setTitle:@"共享" forState:UIControlStateNormal];
            }
            [btn1 addViewClickBlock:^(UIView *view) {
                [MyUiActionSheet showWithActionSheetBlock:^(UIActionSheet * _Nonnull actionSheet, NSInteger buttonIndex) {
                    
                    if (buttonIndex==1) {
                        [weakview1 setAddValue:@"1" forKey:@"data"];
                        [weakbtn1 setTitle:@"自有" forState:UIControlStateNormal];
                    }else if(buttonIndex==2){
                        [weakview1 setAddValue:@"2" forKey:@"data"];
                        [weakbtn1 setTitle:@"共享" forState:UIControlStateNormal];
                    }
                    
                } WithTitle:@"标签" cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"自有",@"共享",nil];
            }];
        }else  if ([titleStr isEqualToString:@"录入者"]) {
            tf1.text=[_DataDic objectForKey:@"invitername"];
            tf1.userInteractionEnabled=NO;
        }else  if ([titleStr isEqualToString:@"跟踪者"]) {
            tf1.text=[_DataDic objectForKey:@"username"];
            
            tf1.userInteractionEnabled=NO;
            
        }
        
//        else  if ([arraytitle isEqualToString:@"<#姓名#>"]) {
//            
//        }else  if ([arraytitle isEqualToString:@"<#姓名#>"]) {
//            
//        }else  if ([arraytitle isEqualToString:@"<#姓名#>"]) {
//            
//        }else  if ([arraytitle isEqualToString:@"<#姓名#>"]) {
//            
//        }
        
        myY=view1.frameYH;;
        
    }
    scrollView.contentHeight=myY;
    kScrollViewCouldScroll(scrollView);
    
}

-(void)reloadScrollView{
NSArray*arraytitle=@[@"姓名",@"性别",@"电话",@"微信",@"邮箱",@"性质",@"公司名称",@"分类",@"备注",@"标签",];
    
    if (_isEdite) {
        arraytitle=@[@"姓名",@"性别",@"电话",@"微信",@"邮箱",@"性质",@"公司名称",@"分类",@"备注",@"标签",@"录入者",@"跟踪者",];
    }
    float myY=0.0;
    for (int i=0; i<arraytitle.count; i++) {
        UIView*view=[self getAddValueForKey:arraytitle[i]];
        if ([view isKindOfClass:[UIView class]]) {
            
            view.frameY=myY;
            
            myY=view.frameYH;
        }
    }
    
    scrollView.contentHeight=myY;
    kScrollViewCouldScroll(scrollView);

}

-(NSString*)getContentWithStr:(NSString*)title{
    UITextField*tf=[[self getAddValueForKey:title] getAddValueForKey:@"tf1"];
    if ([tf isKindOfClass:[UITextField class]]) {
        return tf.text;
    }
    
    return nil;
}
-(NSString*)getDataWithStr:(NSString*)title{
//    UITextField*tf=[[self getAddValueForKey:title] getAddValueForKey:@"tf1"];
//    if ([tf isKindOfClass:[UITextField class]]) {
//        return tf.text;
//    }
    return [[self getAddValueForKey:title] getAddValueForKey:@"data"];
    return nil;
}


-(void)OKBtnClik:(UIButton*)btn{
    __weak __typeof(self) weakSelf = self;
    
    krequestParam
    if ([self.userInfo isEqualToString:@"买家"]) {
        [dictparam setObject:@"1" forKey:@"type"];
    }else{
        [dictparam setObject:@"0" forKey:@"type"];
    }
    
    
    NSMutableArray * imageArr = [[NSMutableArray alloc]init];
    
    for (int i = 0; i < self.imageArray.count - 1; i ++) {
        
        id image = self.imageArray[i];
        if ([image isKindOfClass:[UIImage class]]) {
            
            [imageArr addObject:image];
            
        }
        
    }
    
    NSMutableArray *fileData = [[NSMutableArray alloc] init];
    for (int i = 0; i < imageArr.count; i++) {
        
        UIImage *image = imageArr[i];
        
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:UIImageJPEGRepresentation([[Utility Share]imageWithImageSimple:image scaledToSize:CGSizeMake(image.size.width, image.size.height)], 1),@"fileData",@"path[]",@"fileKey",@"aa.jpg",@"fileName",@"image",@"fileType", nil];
        
        [fileData addObject:dic];
    }
    
    
    if (![[self getContentWithStr:@"姓名"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入姓名"];
        return;
    }else{
        [dictparam setObject:[self getContentWithStr:@"姓名"] forKey:@"name"];
    }
    
    if (![[self getDataWithStr:@"性别"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请选择性别"];
        return;
    }else{
        [dictparam setObject:[self getDataWithStr:@"性别"] forKey:@"sex"];
    }
    
    if (![[self getContentWithStr:@"电话"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入电话"];
        return;
    }else{
        [dictparam setObject:[self getContentWithStr:@"电话"] forKey:@"mobile"];
    }
    
    if (![[self getContentWithStr:@"微信"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入微信"];
        return;
    }else{
        [dictparam setObject:[self getContentWithStr:@"微信"] forKey:@"wechat"];
    }
    
    if (![[self getContentWithStr:@"邮箱"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入邮箱"];
        return;
    }else{
        [dictparam setObject:[self getContentWithStr:@"邮箱"] forKey:@"email"];
    }
    
    if (![[self getDataWithStr:@"性质"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请选择性质"];
        return;
    }else{
        [dictparam setObject:[self getDataWithStr:@"性质"] forKey:@"nature"];
    }
    
    if (![[self getContentWithStr:@"公司名称"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入公司名称"];
        return;
    }else{
        [dictparam setObject:[self getContentWithStr:@"公司名称"] forKey:@"companyname"];
    }
    
    if (![[self getDataWithStr:@"分类"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入分类"];
        return;
    }else{
        [dictparam setObject:[self getDataWithStr:@"分类"] forKey:@"cid"];
    }
    UIButton*btnx=[[self getAddValueForKey:@"备注"] getAddValueForKey:@"btn1"];
    if (btnx.selected) {
        if (![_tv.text notEmptyOrNull]) {
            [SVProgressHUD showErrorWithStatus:@"请填写备注信息"];
            
            return;
        }else{
            [dictparam setAddValue:_tv.text forKey:@"descr"];
//            dataArray=[_imageEditorV getRequsetArrywithkey:@"path" removeServer:NO];;
        }
        
        
    }
  
    
    
    if (![[self getDataWithStr:@"标签"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入标签"];
        return;
    }else{
        [dictparam setObject:[self getDataWithStr:@"标签"] forKey:@"sharetype"];
    }
    
//    if (![[self getContentWithStr:@""] notEmptyOrNull]) {
//        [SVProgressHUD showImage:nil status:@"请输入录入者"];
//        return;
//    }else{
//        [dictparam setObject:[self getContentWithStr:@"录入者"] forKey:@"<##>"];
//    }
//    
//    if (![[self getContentWithStr:@"跟踪者"] notEmptyOrNull]) {
//        [SVProgressHUD showImage:nil status:@"请输入跟踪者"];
//        return;
//    }else{
//        [dictparam setObject:[self getContentWithStr:@"跟踪者"] forKey:@"<##>"];
//    }
    
    
    if (_isEdite) {
        [dictparam setObject:[_DataDic objectForJSONKey:@"id"] forKey:@"id"];
        [dictparam setObject:[_DataDic objectForJSONKey:@"type"] forKey:@"type"];
    }
   
    [dictparam setValue:[self.remArray componentsJoinedByString:@","] forKey:@"pathid"];
    
    [NetEngine uploadAllFileAction:@"customer/updatecustomer" withParams:dictparam fileArray:fileData onCompletion:^(id resData, BOOL isCache) {
        if ([[resData getSafeObjWithkey:@"status"] isEqualToString:@"200"]) {
            [MyUiIAlertView showAlerttWithTitle:@"温馨提示" message:[resData valueForJSONKey:@"info"] cancelButtonTitle:@"确定" otherButtonTitles:nil WithAlertBlock:^(UIAlertView *alertView, NSInteger buttonIndex) {
                [weakSelf backButtonClicked:nil];
                if (weakSelf.allcallBlock) {
                    
                    weakSelf.allcallBlock(nil,200,[resData valueForJSONKey:@"info"]);
                }
            }];
            
        }else{
            [SVProgressHUD showErrorWithStatus:[resData valueForJSONKey:@"info"]];
        }
    } onError:^(NSError *error) {
        
    } withMask:SVProgressHUDMaskTypeBlack];
    
    
}
#pragma mark - 请求数据
-(void)loadDATA{
    krequestParam
    [dictparam setObject:[self.otherInfo objectForJSONKey:@"id"] forKey:@"id"];
    
    [NetEngine createPostAction:@"customer/customer_detail" withParams:dictparam onCompletion:^(id resData, BOOL isCache) {
        if ([[resData getSafeObjWithkey:@"status"] isEqualToString:@"200"]) {
            NSDictionary *dic=[[resData getSafeObjWithkey:@"data"] objectForKey:@"detail"];
            _DataDic=dic;
            NSArray * pathArray = [_DataDic[@"path"] mutableCopy];
            self.pathArray = [[NSMutableArray alloc]initWithArray:pathArray];
            _canEdite=![[[resData getSafeObjWithkey:@"data"] objectForKey:@"isedit"] isEqualToString:@"2"];
            [self addView];
            
            
        }else{
            [SVProgressHUD showErrorWithStatus:[resData valueForJSONKey:@"info"]];
            
        }
    }];
    
}
#pragma mark - 事件监听


#pragma mark - 代理事件
#pragma mark - keyboak
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //注册监听键盘事件
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardDidShow:) name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
}

-(void)handleKeyboardDidShow:(NSNotification *)notification{
    
    NSDictionary *info = [notification userInfo];
    CGRect keyboardFrame;
    [[info objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardFrame];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;
    CGFloat distanceToMove = kbSize.height;
    NSLog(@"---->动态键盘高度:%f",distanceToMove);
#pragma mark zxh UI布局 根据键盘布局
    
    
    scrollView.frame=CGRectMake(X(scrollView), Y(scrollView), W(scrollView),self.view.frame.size.height- Y(scrollView)-distanceToMove);
    
    [WSKeyBoardTool TFscrollview:scrollView];
    
}
- (void)handleKeyboardWillHide:(NSNotification *)notification
{
    
    [UIView animateWithDuration:0.3 animations:^{
        scrollView.frame=CGRectMake(0, 64, kScreenWidth,kScreenHeight-64-40);
    }];
}//
-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

#pragma mark - textfielddelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.view endEditing:YES];
    return YES;
}

#pragma mark - UITextView Delegate Methods
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}
#pragma mark  单击后键盘消失
-(void)tapView
{
    //    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    //    // 连续敲击2次,手势才能识别成功
    //    tap.numberOfTapsRequired = 1;
    //    tap.numberOfTouchesRequired = 1;
    //
    //    // 2.添加手势识别器对象到对应的view
    //    [self.view addGestureRecognizer:tap];
    //
    //    // 3.添加监听方法(识别到了对应的手势,就会调用监听方法)
    //    [tap addTarget:self action:@selector(tapView)];
    
    
    [self.view endEditing:YES];
}
-(void)backButtonClicked:(id)sender{
    
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"CRMList" object:nil];
    
    
    [super backButtonClicked:sender];
}
-(NSMutableArray *)imageArray{
    
    if (!_imageArray) {
        
        _imageArray = [[NSMutableArray alloc]init];
    }
    
    return _imageArray;
}
-(NSMutableArray *)pathArray{
    
    if (!_pathArray) {
        
        _pathArray = [[NSMutableArray alloc]init];
    }
    
    return _pathArray;
}
-(NSMutableArray *)remArray{
    
    if (!_remArray) {
        
        _remArray = [[NSMutableArray alloc]init];
    }
    
    return _remArray;
}
@end
